home *** CD-ROM | disk | FTP | other *** search
/ Suzy B Software 2 / Suzy B Software CD-ROM 2 (1994).iso / extras / boot_up / bmpshow2 / graphics.txt < prev   
Text File  |  1995-04-27  |  8KB  |  200 lines

  1. **************************************************************************
  2. * Direct memory access graphic functions. Created by Robert W Stiles.    *
  3. * See notice at end of file.                                             *
  4. **************************************************************************
  5.  
  6.  
  7. There was a day when I got fed-up with the VDI putpixel and getpixel. There
  8. ploting speed was nothing less then SLOW! So I sent a little time and 
  9. created a few routines myself. No dought there not the fastest, but they
  10. are many times faster then the VDI routines. Here is a list of then and
  11. there use.
  12.  
  13. ***************************************************************************
  14. This is the function you must call before you can use any of the graphics 
  15. function. It's responsible for setting up vector tables and allocating
  16. memory.
  17.  
  18. int pinit(int max_x, int max_y, void *video_buffer, int planes);
  19.           max_x = maximum resoltion in the x direction.
  20.           max_y = maximum resoltion in the y direction.
  21.    video_buffer = is the location of video ram or buffer.
  22.          planes = number of video planes.
  23.          
  24. Example 1: To run on ATARI ST monochrome display.
  25.    pinit(640, 400, Logbase(), 1);
  26.  
  27. Example 2: To run on FALCON030 256 color VGA display.
  28.    pinit(640, 480, Logbase(), 8);
  29.  
  30. Example 3: If you dont want to worry about it. Let VDI get the information.
  31.            
  32.       appl_init();
  33.       for ( i = 1; i < 10; work_in[i++] = 1 );
  34.       work_in[10] = 2;
  35.       phys_handle = graf_handle( &gl_wchar, &gl_hchar, &gl_wbox, &gl_hbox );
  36.       work_in[0]  = handle = phys_handle;
  37.       v_opnvwk( work_in, &handle, work_out );
  38.       vq_extnd(handle, 1, extend_out);
  39.       pinit(work_out[0]+1, work_out[1]+1, (void *)Logbase(), extend_out[4]);
  40.       ... (What ever you need to do).
  41.       pexit();
  42.       v_clsvwk( handle );
  43.       appl_exit( );
  44.  
  45. Note: max_x and max_y doesnt have to be any ST/TT/FALCON standard 
  46.       resolution. Video_buffer can be any memory location. But you must
  47.       make sure there is enough memory for the give resolution selected.
  48.       Generally planes will be one of the following. 1,2,4,8,16. Value 16
  49.       isnt the number of planes. In this case it will configure the grahics
  50.       functions to work in HIGHCOLOR mode. Which is 16 bits per pixel.
  51. ***************************************************************************
  52. This function releases allocated memory by.
  53.  
  54. void pexit(void);
  55.  
  56. Example: 
  57.    pexit();
  58.  
  59. ***************************************************************************
  60. The following routines are the indirect graphics routines. If you use
  61. these it will make proramming easier between the different resolutions. 
  62. Because pinit() will assign the correct graphic function to the resolution
  63. selected.
  64. ***************************************************************************
  65. Plot a pixel at x,y with index color.
  66.  
  67. int (*p_pixel)(int x, int y, int color);
  68.  
  69. Example: To place a pixel at location 100, 100, with color 2.
  70.    (*p_pixel)(100, 100, 2);
  71.    
  72. ***************************************************************************
  73. Get the color index value at location x,y.
  74.  
  75. int (*g_pixel)(int x, int y);
  76.  
  77. Example: To return the color value a location 100, 100
  78.    (*g_pixel)(100, 100, 2);
  79.  
  80. ***************************************************************************
  81. Draw a line from x1,y1 to x2,y2 with index color. 
  82.  
  83. int (*d_line)(int x1, int y1, int x2, int y2, int color);
  84.  
  85. Example: To plot a line from 100,100 to 200,200 with color 3
  86.    (*d_line)(100, 100, 200, 200, 3);
  87.  
  88. ***************************************************************************
  89. Draw a horizontal line from x1,x2 on y with index color. 
  90.  
  91. int (*d_hline)(int x1, int x2, int y, int color);
  92.  
  93. Example: To plot a horizontal line from 100,100 on 200 with color 3
  94.    (*d_hline)(100, 100, 200, 3);
  95.  
  96. ***************************************************************************
  97. Convert color index to raw data, directly usable in ATARI video ram. This 
  98. is usefull when plot data that runs in horizonal directions. Like .GIF, 
  99. .BMP, and other picture files. However it does have a few restrictions. 
  100.  
  101. 1. Both buffers have to be WORD aligned.
  102. 2. Conversion is done in groups of 16 bytes (color indexes).
  103.  
  104. Both buffers can be the same. If the destination data location is the same
  105. as the source data. Then the source data will overwrite the destination 
  106. after the conversion is completed.
  107.  
  108. This routine is much faster the p_pixel() when ploting data in sequence.
  109. It's also written in assembler. Which means it will only run with 'C' 
  110. function compiled with Pure 'C'. Pure 'C' uses registers to pass data. 
  111. If your compiler uses a different method you'll have to modify the source.
  112.  
  113. int (*byte2raw)(char *colors, char *buffer);
  114.  
  115. Example: To plot a complete horizontal line of data to the video ram.
  116.  
  117.       char color[640] = { 1,4,35,6,7,44,44,...};
  118.       
  119.       screen = Logbase();   
  120.       
  121.       for (x = 0; x < 640;) 
  122.       {
  123.          screen += (*byte2raw)(&color[x], screen);
  124.          x += 16;
  125.          screen += (*byte2raw)(&color[x], screen);
  126.          x += 16;
  127.          screen += (*byte2raw)(&color[x], screen);
  128.          x += 16;
  129.          screen += (*byte2raw)(&color[x], screen);
  130.          x += 16;
  131.       }
  132.  
  133. byte2raw() returns the number of bytes written to the buffer. This makes
  134. incrementing the buffer easier. Since each video resolution will require
  135. different amounts of memory.
  136.  
  137. ***************************************************************************
  138. Draw a circle at coordinates x,y with radius and color. 
  139.  
  140. void circle(int x, int y, int radius, int color);
  141.  
  142. Example: To display a circle at position 100,100 with a radius of 50 using
  143.          the color index of 3.
  144.          
  145.    circle(100, 100, 50, 3);
  146.    
  147. ***************************************************************************
  148. Draw a filled circle at coordinates x,y with radius and color.
  149.  
  150. void disk(int x, int y, int radius, int color);
  151.  
  152. Example: To display a filled circle at position 100,100 with a radius of 
  153.          50 using the color index of 3.
  154.  
  155.    disk(100, 100, 50, 3);
  156.    
  157. ***************************************************************************
  158. These are the direct calling functions.
  159. ***************************************************************************
  160. See p_pixel for there use:
  161.  
  162. int set_pixel1(int x, int y, int color);  /* Monochrome */
  163. int set_pixel2(int x, int y, int color);  /* 4 color    */
  164. int set_pixel4(int x, int y, int color);  /* 16 color   */
  165. int set_pixel8(int x, int y, int color);  /* 256 color  */
  166. int set_pixel16(int x, int y, int color); /* Highcolor  */
  167. ***************************************************************************
  168.  
  169. See g_pixel for there use:
  170. int get_pixel1(int x, int y);  /* Monochrome */
  171. int get_pixel2(int x, int y);  /* 4 color    */
  172. int get_pixel4(int x, int y);  /* 16 color   */
  173. int get_pixel8(int x, int y);  /* 256 color  */
  174. int get_pixel16(int x, int y); /* Highcolor  */
  175. ***************************************************************************
  176.  
  177. See byte2raw for there use:
  178. int byte2raw8(char *color, char *buffer);  /* Monochrome */
  179. int byte2raw4(char *color, char *buffer);  /* 4 color    */
  180. int byte2raw2(char *color, char *buffer);  /* 16 color   */
  181. int byte2raw1(char *color, char *buffer);  /* 256 color  */
  182. ***************************************************************************
  183.  
  184.  
  185. NOTICE: Since the files herein are only source code. And once released 
  186. into the public domain. I will not have much control over what happens
  187. to it. So here goes...
  188.  
  189. User or programmer are responsible for any negative effects that results 
  190. from the use of this software in either hardware or softwware. No
  191. warranties are in effect either expressed or implied. blaw, blaw, blaw....
  192.  
  193. Copyright (C) 1994 by Robert W Stiles
  194. I hereby grant the release of this source code into the public domain for
  195. free distribution and use. All other rights (if any) are reserved.
  196.  
  197. I can be reached at the following locations.
  198. Amature Packet Radio: KD6GEO @ N5RKJ.#CTX.TX.USA.NOAM
  199. Internet: r.stilesstil@genis.com
  200. Genie: R.STILESSTIL